package com.bra.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bra.R;
import com.bra.bean.HomeMessageBean;
import com.bra.bean.HomeType;
import com.bra.ui.activity.ArticleListActivity;
import com.bra.view.Home_Hsv_Type;
/**
 * 首页的信息列表类型adapter
 * @author lenovo
 *
 */
public class Home_Type_adapter extends BaseAdapter{

    private Context  context;
	private Home_hsc_adapter adapter;
	private List<HomeType>type_lists;
	private List<HomeMessageBean>homepages=new ArrayList<HomeMessageBean>();
	
	public Home_Type_adapter(Context  context, List<HomeType>type_lists/*, List<Home_ImageBean> homepages*/) {
		this.context=context ;
		this.type_lists=type_lists;
		this.homepages = homepages;	
		
   	   /*  if(adapter==null){
			adapter = new Home_hsc_adapter(context, homepages);
		}	*/
	}
	
	public void addData(List<HomeType> homepages) {
		// TODO Auto-generated method stub
		this.type_lists.addAll(type_lists);
	}

	public void setData(List<HomeType> type_lists) {
		this.type_lists = type_lists;
	}
	public int getCount() {
		return type_lists.size();
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView==null){
			convertView=View.inflate(context, R.layout.home_sc_type_item, null);
			holder=new ViewHolder();
			holder.home_sc_item_name=(TextView) convertView.findViewById(R.id.home_sc_item_name);
			holder.home_more=(TextView) convertView.findViewById(R.id.home_more);
			holder.home_sc_type=(Home_Hsv_Type) convertView.findViewById(R.id.home_sc_type);							
		//	holder.home_sc_type.setAdapter(adapter);			
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}	
		holder.home_sc_item_name.setText(type_lists.get(position).getTitle());		
		holder.home_more.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent zixun = new Intent(context,ArticleListActivity.class);
				context.startActivity(zixun);			
			}
		});
		return convertView;
	}
public  class ViewHolder{
	public   TextView  home_sc_item_name,home_more;
	private Home_Hsv_Type home_sc_type;
	
}
	@Override
	public Object getItem(int position) {
		return homepages.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

}
